package com.android.hedgehog;

import android.graphics.Color;

import com.android.hedgehog.framework.Graphics;

public class Box {
	public int x, y;
	public int width, height;
	int fontNumber;
	int fontSize;
	int strokeWidth;
	int fontYPos;
	Graphics graphics;
	String text;
	int backgroundColor;
	int textColor;
	int borderColor;

	public Box(Graphics graphics, String text, int x, int y, int width, int height) {
		this.graphics = graphics;
		this.text = text;
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
	}

	public Box(Graphics graphics, String text, int boxStyle, int x, int y, int width, int height) {
		this.graphics = graphics;
		this.text = text;
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		fontYPos = (int) (y + height * .77);
		fontSize = height / 2;
		setBoxStyle(boxStyle);
	}

	private void setBoxStyle(int boxStyle) {
		if (boxStyle == 0) {
			fontNumber = 2;
			strokeWidth = 2;
			backgroundColor = Color.GRAY;
			borderColor = Color.DKGRAY;
			textColor = Color.WHITE;
		}
	}

	/**
	 * Manually configured Box
	 * 
	 * @param graphics
	 * @param text
	 * @param fontNumber
	 * @param fontSize
	 * @param strokeWidth
	 * @param x
	 * @param y
	 * @param width
	 * @param height
	 * @param backgroundColor
	 * @param borderColor
	 * @param textColor
	 */
	public Box(Graphics graphics, String text, int fontNumber, int fontSize, int strokeWidth, int x, int y,
			int width, int height, int backgroundColor, int borderColor, int textColor) {
		this.graphics = graphics;
		this.text = text;
		this.fontNumber = fontNumber;
		this.fontSize = fontSize;
		this.strokeWidth = strokeWidth;
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		this.backgroundColor = backgroundColor;
		this.borderColor = borderColor;
		this.textColor = textColor;

		fontYPos = (int) (y + height * .77);
	}

	/**
	 * To Reset Position to new location
	 * 
	 * @param x
	 * @param y
	 * @param width
	 * @param height
	 */
	public void setPosition(int x, int y, int width, int height) {
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
	}

	public boolean click(int xPos, int yPos) {
		if (xPos > x && xPos < x + width && yPos > y && yPos < y + height)
			return true;
		return false;
	}

	public void draw() {
		graphics.drawUniversalRect(x, y, width, height, false, true, 1, 255, backgroundColor);
		graphics.drawUniversalRect(x, y, width, height, false, false, strokeWidth, 255, borderColor);
		graphics.drawUniversalText(text, fontNumber, true, x + (width / 2), fontYPos, fontSize, 255,
				textColor);
	}

}
